#ifndef WEBSERVER_LOCKER_H
#define WEBSERVER_LOCKER_H

#include <exception>
#include <pthread.h>
#include <semaphore.h>

/**
 * @brief 封装Unix信号量
 * 信号量
 */
class Sem
{
public:
    Sem();
    Sem(int _num);
    ~Sem();
public:
    bool Wait();
    bool Post();
private:
    sem_t m_sem;
};

/**
 * @brief 封装Unix互斥锁
 * 互斥锁
 */
class Locker
{
public:
    Locker();
    ~Locker();
public:
    bool Lock();
    bool UnLock();
    pthread_mutex_t* Get();
private:
    pthread_mutex_t m_mutex;
};

/**
 * @brief 用于线程唤醒等操作
 * 条件变量
 */
class Cond
{
public:
    Cond();
    ~Cond();
public:
    bool Wait(pthread_mutex_t* _mutex);
    bool TimeWait(pthread_mutex_t* _mutex,timespec _t);
    bool Signal();
    bool Broadcast();
private:
    pthread_cond_t m_cond;
};

#endif // WEBSERVER_LOCKER_H